#pragma once

#include "LatoolException.h"

namespace LatoolNet {
	using namespace System;

	///
	///<summary>
	/// This class solves a least square problem.
	///</summary>
	///
	public ref class LeastSquare {
	private:
		LeastSquare(){};
	public:

		///
		///<summary>
		/// Solves a least square problem.  
		/// The result is overritten to the second argument.
		///</summary>
		///
		static void Solve(Matrix ^ a, Matrix ^ b) {
			
			if (a->Type != MatrixType::DoubleGeneral || 
				b->Type != MatrixType::DoubleGeneral) {
				throw gcnew LatoolException("Only double general matrix is supported.");
			}

			DoubleGeneralMatrix ^ da = (DoubleGeneralMatrix^) a->GetInternalMatrix();
			IMatrix ^ ilb = b->GetInternalMatrix();

			char m_trans = 'N';
			da->SolveLeastSquare(m_trans, ilb);
		};
	};

}